﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model;
using l1cs.server.serverpackets;

namespace l1cs.server.clientpackets
{
    public class C_Restart : ClientBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( C_Restart ).FullName );
        private const String _C_RESTART = "[C] C_Restart";

        public C_Restart( byte[] abyte0, ClientThread clientthread )
            : base( abyte0 )
        {
            L1PcInstance pc = clientthread.getActiveChar();

            int[] loc;

            if ( pc.getHellTime() > 0 )
            {
                loc = new int[3];
                loc[0] = 32701;
                loc[1] = 32777;
                loc[2] = 666;
            }
            else
            {
                loc = Getback.GetBack_Location( pc, true );
            }

            pc.removeAllKnownObjects();
            pc.broadcastPacket( new S_RemoveObject( pc ) );

            pc.setCurrentHp( pc.getLevel() );
            pc.set_food( 40 );
            pc.setDead( false );
            pc.setStatus( 0 );
            L1World.getInstance().moveVisibleObject( pc, loc[2] );
            pc.setX( loc[0] );
            pc.setY( loc[1] );
            pc.setMap( (short)loc[2] );
            pc.sendPackets( new S_MapID( pc.getMapId(), pc.getMap().isUnderwater() ) );
            pc.broadcastPacket( new S_OtherCharPacks( pc ) );
            pc.sendPackets( new S_OwnCharPack( pc ) );
            pc.sendPackets( new S_CharVisualUpdate( pc ) );
            pc.startHpRegeneration();
            pc.startMpRegeneration();
            pc.sendPackets( new S_Weather( L1World.getInstance().getWeather() ) );
            if ( pc.getHellTime() > 0 )
            {
                pc.beginHell( false );
            }
        }

        override
        public String getType()
        {
            return _C_RESTART;
        }
    }
}